package com.sixteen.theGreat.workbench.service.impl;

import com.sixteen.theGreat.commons.entity.ReturnObject;
import com.sixteen.theGreat.workbench.entity.FriendList;
import com.sixteen.theGreat.workbench.mapper.FriendListMapper;
import com.sixteen.theGreat.workbench.service.FriendListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("friendListService")
public class FriendListServiceImpl implements FriendListService {
    @Autowired
    private FriendListMapper friendListMapper;

    /**
     * 添加好友列表的一条数据
     * @param friendList
     * @return
     */
    @Override
    public Object addFriendList(FriendList friendList) {
        int reg = 0;
        ReturnObject returnObject=new ReturnObject();
        try {
            reg = friendListMapper.insertFriendList(friendList);
            if (reg > 0){
                returnObject.setCode(1);
            }else {
                returnObject.setCode(0);
                returnObject.setMessage("好友代码不存在...");
            }
        }catch (Exception e){
            returnObject.setCode(0);
            returnObject.setMessage("系统繁忙,请稍候...");
            e.printStackTrace();
        }finally {
            return returnObject;
        }
    }

    /**
     * 通过useId 查询我的所有好友
     * @param userId
     * @return
     */
    @Override
    public List<FriendList> queryFriendListByUserId(String userId) {
        return friendListMapper.selectFriendListByUserId(userId);
    }


}
